﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VISS.API.Users {

    /// <summary>
    /// This Interface is only used for Web Admin
    /// </summary>
    public interface IUserAdmin {
        /// <summary>
        /// Insert new user.
        /// Every new user will be inserted into these tables:
        /// User, UserGeneralProfile, UserContactInfo, UserAppearanceProfile, UserCultureProfile,
        /// UserFamilyProfile, UserLivingProfile.
        /// </summary>
        /// <param name="item">The UserAdminEnt item (can be null).</param>
        /// <param name="pItem">The UserGeneralProfileEnt item (can be null).</param>
        /// <param name="cItem">The UserContactInfoEnt item (can be null).</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool Insert(UserAdminEnt item, UserGeneralProfileEnt pItem, UserContactInfoEnt cItem);

        /// <summary>
        /// Update email of user
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateEmail(UserAdminEnt item);
        /// <summary>
        /// Update email of user
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <param name="email">The email.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateEmail(string userKey, string email);
        /// <summary>
        /// Update password of user
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdatePassword(UserAdminEnt item);
        /// <summary>
        /// Update password of user
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <param name="password">The password.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdatePassword(string userKey, string password);
        /// <summary>
        /// Update short link of user
        /// </summary>
        /// <param name="item">The UserAdminEnt item.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateSLink(UserAdminEnt item);
        /// <summary>
        /// Update short link of user
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <param name="sLink">The short link.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateSLink(string userKey, string sLink);
        /// <summary>
        /// Update short link expired date
        /// </summary>
        /// <param name="item">The UserAdminEnt item.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateSLinkExpiredDate(UserAdminEnt item);
        /// <summary>
        /// Update short link expired date
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <param name="sLinkExpiredDate">The s link expired date.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateSLinkExpiredDate(string userKey, DateTime sLinkExpiredDate);
        /// <summary>
        /// Update info of short link and expired date
        /// </summary>
        /// <param name="item">The UserAdminEnt item.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateSLinkAndSLinkExpiredDate(UserAdminEnt item);
        /// <summary>
        /// Update info of short link and expired date
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <param name="sLink">The s link.</param>
        /// <param name="sLinkExpiredDate">The s link expired date.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateSLinkAndSLinkExpiredDate(string userKey, string sLink, DateTime sLinkExpiredDate);
        /// <summary>
        /// Update status of user: Actived, Disabled, Deleted, Verified, ...
        /// </summary>
        /// <param name="item">The UserAdminEnt item.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateStatus(UserAdminEnt item);
        /// <summary>
        /// Update status of user: Actived, Disabled, Deleted, Verified, ...
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <param name="status">The status.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UpdateStatus(string userKey, EUserStatus status);

        /// <summary>
        /// Disable an account of user
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool DisableUser(string userKey);
        /// <summary>
        /// Undisable an account of user
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UnDisableUser(string userKey);
        /// <summary>
        /// Delete an user account
        /// the account is not really delete, just add "Deleted" status to user status
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool DeleteUser(string userKey);
        /// <summary>
        /// Undelete an user account
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UnDeleteUser(string userKey);
        /// <summary>
        /// Set "Verified" status for an user account
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool VefifyUser(string userKey);
        /// <summary>
        /// Remove "Verified" status for an user account
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool UnVefifyUser(string userKey);

        /// <summary>
        /// Get info of an user account with extra info
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <returns>Return UserAdminEnt if exists, otherwise return null.</returns>
        UserAdminEnt GetByUserKey_Admin(string userKey);
        /// <summary>
        /// Get info of an user account with extra info by email
        /// </summary>
        /// <param name="email">The email.</param>
        /// <returns>Return UserAdminEnt if exists, otherwise return null.</returns>
        UserAdminEnt GetByEmail(string email);
        /// <summary>
        /// Get user accounts by some condition
        /// </summary>
        /// <param name="gender">The gender.</param>
        /// <param name="status">The status.</param>
        /// <param name="page">The page number.</param>
        /// <param name="recordPerPage">The record per page.</param>
        /// <param name="totalRecord">The total record.</param>
        /// <returns>
        /// Return list of UserAdminEnt if exists records match conditions, otherwise return empty list.
        /// </returns>
        List<UserAdminEnt> GetWithConditionAndPaging(EUserGender gender, EUserStatus status, bool haveAvatar, int page, int recordPerPage, out long totalRecord);

        /// <summary>
        /// Reset password of an user account.
        /// New password is random string with 6 character
        /// </summary>
        /// <param name="userKey">The user key.</param>
        /// <param name="password">The password.</param>
        /// <returns>
        /// Return true if success, otherwise return false
        /// </returns>
        bool ResetPassword(string userKey, out string password);

        //Report

        /// <summary>
        /// Get total count of user
        /// </summary>
        /// <returns>number of user.</returns>
        long CountUser();
        /// <summary>
        /// Get count of activated user
        /// </summary>
        /// <returns>number of user.</returns>
        long CountActivedUser();
        /// <summary>
        /// Count user that login after a specified time
        /// </summary>
        /// <param name="startTime">The start time.</param>
        /// <returns>Number of user.</returns>
        long CountByLastLogin(DateTime startTime);
        
        //Search

        /// <summary>
        /// Search by name of user (not implemented)
        /// </summary>
        /// <param name="nameTemplate">The name template.</param>
        /// <param name="page">The page number.</param>
        /// <param name="recordPerPage">The record per page.</param>
        /// <param name="totalRecord">The total record.</param>
        /// <returns>
        /// Return list of UserAdminEnt if exists records match conditions, otherwise return empty list.
        /// </returns>
        List<UserAdminEnt> SearchByName(string nameTemplate, int page, int recordPerPage, out long totalRecord);
        /// <summary>
        /// Search by email of user.
        /// can use %[SearchTerm]% to search similar email
        /// </summary>
        /// <param name="emailTemplate">The email template.</param>
        /// <param name="page">The page number.</param>
        /// <param name="recordPerPage">The record per page.</param>
        /// <param name="totalRecord">The total record.</param>
        /// <returns>
        /// Return list of UserAdminEnt if exists records match conditions, otherwise return empty list.
        /// </returns>
        List<UserAdminEnt> SearchByEmail(string emailTemplate, int page, int recordPerPage, out long totalRecord);
        /// <summary>
        /// Search by mobile phone of user
        /// can use %[SearchTerm]% to search similar mobile phone
        /// </summary>
        /// <param name="mobiPhoneTemplate">The mobile phone template.</param>
        /// <param name="page">The page number.</param>
        /// <param name="recordPerPage">The record per page.</param>
        /// <param name="totalRecord">The total record.</param>
        /// <returns>
        /// Return list of UserAdminEnt if exists records match conditions, otherwise return empty list.
        /// </returns>
        List<UserAdminEnt> SearchByMobiPhone(string mobiPhoneTemplate, int page, int recordPerPage, out long totalRecord);        
    }
}
